local DState = @@CLASS("DrawState")

@@EXTEND(DState,
	 {
	    think_circle = {
	       radius = 1,
	       x = 0,
	       y = 0,
	       color = { r = 1, g = 1, b = 1, a = 1 },
	       @@SFN(draw,
		     local color = self.color
		     @@SET_CL(color.r, color.g, color.b, color.a)
		     $LG.circle('fill', self.x, self.y, self.radius)
		    )
	    },
	    
	    @@SFN(start, unit,
		  self.unit = unit
		  self.think_circle.x = self.unit.x
		  self.think_circle.y = self.unit.y
		 ),

	    @@SFN(update, dt,
		  return
		 ),

	    @@SFN(draw,
		  local unit = self.unit
		  unit.utype.symbol:draw(unit.x, unit.y)
		  if unit:is_hovered() or unit.selected then
		     $LG.print(unit.name, unit.x-4, unit.y-8, 0, .3, .3)
		  end

		  if unit.selected then
		     --unit._path_handler:draw()
		     @@RECT(unit.x, unit.y, 8, 8, nil, #446699)
		     $LG.print(unit:get_velocity_length(), unit.x, unit.y-2, nil, .2)
		  end

		  -- if self.draw_think then
		  --    self.think_circle.x, self.think_circle.y = unit:get_position()
		  --    self.think_circle:draw()
		  -- end

		  -- if unit.objective then
		  --    @@RECT(unit.objective.x*8, unit.objective.y*8, 8, 8, nil, #FFFFFF)
		  -- end
		 ),

	    @@SFN(show_think,
		  if self.draw_think then return end
		  self.draw_think = true
		  self.unit.timer:tween(1, self.think_circle.color, { a = 1 },
					'linear', function () self.draw_think = nil end)
		 ),

	})

return DState
